package com.nwpusp.display.views.components;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;

import com.example.petssports.R;
import com.nwpusp.display.GlobalVar;

public class HeaderCombination extends View{
	
	public Bitmap header;
	public Bitmap name;
	public Bitmap combination;
	public float x;
	public float y;
	public float scale;
	public int headerIndex;
	public float width;
	public float height;
	public int index;
	public String nameStr;
	
	
	public HeaderCombination(Context view,float scale,int index,String nameStr){
		super(view);
		this.scale = scale;
		this.index = index;
		this.nameStr = nameStr;
		getBitmapSource();
		header = GlobalVar.VerticalScale(header,scale);
		width = header.getWidth();
		height = header.getHeight();
		name = GlobalVar.HorizontalScaleFixWidth(name,width*(float)0.8);
		name = GlobalVar.DrawSubList(name.getWidth(), name.getHeight(), name, nameStr,24);
		combination = Add2Bitmap(header,name);
	}
	
	public void setLocation(float x ,float y){
		this.x = x;
		this.y = y;
	}
	
	private void getBitmapSource(){
		switch(index){     
			case 1:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.xiong);
				break;
			}
			case 2:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.niu);
				break;
			}
			case 3:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.ji);
				break;
			}
			case 4:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.tu);
				break;
			}
			case 5:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.zhu);
				break;
			}
			case 6:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.yang);
				break;
			}
			default:break;
		}
		name = BitmapFactory.decodeResource(getResources(), R.drawable.headername);
	}

	public Bitmap draw(){
		return combination;
	}
	
	public Bitmap Add2Bitmap(Bitmap SourceBitmap1,Bitmap SourceBitmap2){
		 int bgWidth;
		 int bgHeight;
		 int bg1Width = SourceBitmap1.getWidth(); 
		 int bg2Width = SourceBitmap2.getWidth(); 
		 if(bg1Width>bg2Width)
			 bgWidth = bg1Width;
		 else 
			 bgWidth = bg2Width;
		 int bgHeight1 = SourceBitmap1.getHeight();
		 int bgHeight2 = SourceBitmap2.getHeight();
       bgHeight = bgHeight1;   
       Bitmap newbmp = Bitmap.createBitmap(bgWidth, bgHeight, Bitmap.Config.ARGB_8888);  
       Canvas cv = new Canvas(newbmp);    
       cv.drawBitmap(SourceBitmap1, (bgWidth-bg1Width)/2, 0, null); 
       cv.drawBitmap(SourceBitmap2, (bgWidth-bg2Width)/2, bgHeight-bgHeight2*2, null);
       cv.save(Canvas.ALL_SAVE_FLAG);  
       cv.restore();  
       return newbmp;   
	}
}

